#include"Comm.hpp"
#include<unistd.h>

int main()
{
    Fifo fifo(Path);
    int rfd = open(Path,O_RDONLY);
    if(rfd<0)
    {
        cerr<<"open file fail,erron:"<<errno<<"errno string"<<strerror(errno)<<endl;
        return 1;
    }
    // 如果写端没有被打开,但是读端先被打开了,此时读端就会被阻塞,直到写端被打开,读端open才会返回.
    cout<<"open file success!"<<endl;
    char buffer[1024];
    while(true)
    {
        ssize_t n = read(rfd,buffer,sizeof(buffer)-1);
        if(n>0)
        {
            buffer[n] = 0;
            cout<<"cilent say"<<buffer<<endl;
        }
        else if(n==0)
        {
            cout<<"client quit! me too!!"<<endl;
            break;
        }
        else
        {
            cerr<<"read file fail,erron:"<<errno<<"errno string"<<strerror(errno)<<endl;
            break;
        }
    }
    close(rfd);
    sleep(1);
    return 0;
}